import { type Ref, shallowRef, watch } from 'vue';
import type MxpToast from '@/mxp-ui/mxp-toast/mxp-toast.vue';
import { useAppStore } from '@/pinia/app';

/** 注册Toast */
function useMxpToastRefHooks(): Ref<InstanceType<typeof MxpToast> | null> {
  const mxpTooastRef = shallowRef<InstanceType<typeof MxpToast> | null>(useAppStore().mxpToastRef);

  watch(
    () => useAppStore().mxpToastRef,
    (val) => {
      mxpTooastRef.value = val;
    }
  );
  return mxpTooastRef;
}

export default useMxpToastRefHooks;
